home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Strange looking cast in lvalue
- Date: 6 Apr 1996 10:20:09 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4k5ggp$1mr@sparcserver.lrz-muenchen.de>
- References: <4k4s8q$3sv@nuscc.nus.sg>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- eng30403@leonis.nus.sg (Tey Chee Meng) writes:
-
- >(FARPROC)fnSnmpStrToOid=GetProcAddress(hinstWinSNMP,"_SNMPSTRTOOID");
-
- > Can anyone explain the effect, if any, of that (FARPROC) cast on the
- >LHS of the expression ? fnSnmpStrToOid is a pointer to a function.
-
- And a cast expression is not an lvalue, so the expression does not
- make too much sense.
-
- >GetProcAddress returns a pointer to a function as well but is of
- >different type from fnSnmpStrToOid. Arent cast always used on the RHS of
- >assignment expressions ?
-
- Right! Well, in fact, casts _can_ be used in the LHS of an assignment
- expression, if the LHS still renders an lvalue. Consider:
-
- struct foo
- {
- int fred;
- char barney[10];
- };
-
- void
- set_fred(void *p)
- {
- ((struct foo *)p)->fred = 42;
- }
-
- In this case, we have a cast expression on the LHS of an assignment
- operator, but the LHS still is an lvalue.
-
- > I found this code in the windows SDK help, but thought it is more
- >a 'C' question than a windows question. Thanks.
-
- A question does not come off-topic because it uses a certain API, if
- the question is a question about the C programming language, not about
- the API.
-
- OTOH, sometimes it is quite useful to avoid API functions if a potential
- responder will have to compile your code to answer your question,
- because system or even API specific things might not be available
- to him/her.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-
-